<?php
header('Content-Type: text/html; charset=UTF-8');

$url = "http://moodle.codigoaberto.eu/webservice/examesNacionais/exame/";
$exame_url = $url .".json";
$exame_json = file_get_contents($exame_url);

if ($exame_json=== false) {
	print 'Webservice não encontrado';
} else {
	$lista_exames = json_decode($exame_json);
	print "<table border='1'><thead><th>Início</th><th>Exame</th>";
    	print "<th>Código</th><th>Tipo de prova</th><th>Componente</th>";
    	print "<th>Duração</th><th>Tolerância</th></thead><tbody>";
	foreach($lista_exames->{"exameSet"} as $exame){ 

		$disciplina_codigo = $exame->{"disciplina_codigo"};
    		$url = "http://moodle.codigoaberto.eu/webservice/examesNacionais/disciplina/";
    		$disciplina_url = $url . $disciplina_codigo .".json";
    		$disciplina_json = file_get_contents($disciplina_url);

		if ($disciplina_json === false) {
		    	print 'Webservice não encontrado';
		    } else {
		    	$disciplina = json_decode($disciplina_json);
			print "<tr><td>";
			print date('Y-m-d G:i', $exame->{"inicio"});
			print "&nbsp;</td><td>";
			print $disciplina->{"disciplina"}->{"nome"};
			print "&nbsp;</td><td>";
			print $exame->{"disciplina_codigo"};
			print "&nbsp;</td><td>";
			print $disciplina->{"disciplina"}->{"tipo_prova"};
			print "&nbsp;</td><td>";
			print $exame->{"componente"};
			print "&nbsp;</td><td>";
			print date('G:i', $exame->{"duracao"});
			print "&nbsp;</td><td>";
			print date('G:i', $exame->{"tolerancia"});
			print "&nbsp;</td></tr>";
		    }
	}
	print "</tbody></table>";
}

?>  
